package com.cn.controller;

import com.cn.dao.User;
import com.cn.server.Impl.UserServerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class LoginController {
    @Autowired
    private User user;
    @Autowired
    private UserServerImpl userServerImpl;
    @RequestMapping("/")
    public String Login(){
        return "login";
    }
    @RequestMapping("/reg")
    public String Reg(){
        return "reg";
    }
    @RequestMapping("/index")
    public String index(String email,String password,Model model){
        user = userServerImpl.getUserByEmail(email);
        System.out.println(password);
        if(user != null){
            if(user.getPassword().equals(password)){
                return "index";
            }else {
                model.addAttribute("msg","用户密码错误");
                return "redirect:/";
            }
        }else{
            model.addAttribute("msg","用户邮箱不存在");
            return "redirect:/";
        }

    }
}
